package com.base.cn.platform.os.controller.user.member;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.service.manage.user.member.CusUserMemberBuyRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 后台用户会员记录管理
 *
 * @author ll
 * @create 2018-04-26
 */
@Controller
@RequestMapping("/admin/user/cus")
public class AdminUserMemberRecordController extends AdminBaseController {

    @Autowired
    private CusUserMemberBuyRecordService cusUserMemberBuyRecordService;
    /**
     * 会员记录页面
     * @return
     */
    @RequestMapping("/toCusUserMemberRecordListPage")
    public String toCusUserMemberRecordListPage(){
        return resultPage("/user/member/member-buy-record-list");
    }

    /**
     * 会员列表页面
     * @param model
     * @param memberRecord
     * @param currentPage
     * @return
     */
    @RequestMapping("/ajaxCusUserMemberRecordList")
    public String ajaxCusUserMemberRecordList(Model model,
                                              @RequestBody Map<String,Object> memberRecord,
                                              @RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage){
        Map<String,Object> dataMap =cusUserMemberBuyRecordService.queryUserMemberBuyRecordListPage(memberRecord,currentPage);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/user/member/ajax-member-buy-record-list");
    }

    /**
     * 修改会员记录状态
     * @param id
     * @param status
     * @return
     */
    @RequestMapping("/updateMemberRecordStatus")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.USER, action = "修改学员会员商品的状态")
    public Map<String,Object> updateMemberRecordStatus(@RequestParam("id")BigDecimal id,
                                                       @RequestParam("status")Integer status){
        return cusUserMemberBuyRecordService.updateUserMemberBuyRecordStatus(id,status);
    }
}
